(* Copyright 2007 dnAnalytics Project.
 *
 * Contributors to this file:
 * Jurgen Van Gael
 *
 * This file is part of dnAnalytics.  dnAnalytics is licensed under the 
 * Microsoft Public License. See License.txt for a complete copy of the
 * license.
 *)
#light

namespace dnAnalytics.LinearAlgebra

open dnAnalytics.LinearAlgebra

/// A module which implements functional sparse vector operations.
module SparseMatrix =

    /// Create the identity matrix.
    let identity (n:int) =
        let A = new SparseMatrix(n,n)
        for i=0 to n-1 do
            A.[i,i] <- 1.0
        A
    
    /// Create a matrix from a list of float lists. Every list in the master list specifies a row.
    let of_list (rows: int) (cols: int) (fll: list<int * int * float>) =
        let A = SparseMatrix(rows, cols)
        fll |> List.iter (fun (i, j, x) -> A.[i,j] <- x)
        A
    
    /// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a row.
    let of_seq (rows: int) (cols: int) (fss: #seq<int * int * float>) =
        let A = SparseMatrix(rows, cols)
        fss |> Seq.iter (fun (i, j, x) -> A.[i,j] <- x)
        A